%% Created Time:  Mon Apr 16 17:03:45 2012

-module(id_allocate).
-export([start/0, stop/0, get_id/0, get_id/1]).
-author("Charon <kevinlpcd@gmail.com>").
-vsn("id_allocate 0.1").
-ifdef(debug).
-define(TRACE(X), io:format("TRACE ~p:~p ~p. [@~p]~n", [?MODULE, ?LINE, X, ?FILE])).
-else.
-define(TRACE(X), void).
-endif.

start() ->
	crypto:start().

get_id() ->
	<<I:160/integer>> = crypto:sha(term_to_binary({make_ref(), now()})),
	ID = lists:flatten(io_lib:fwrite("~40..0s", [erlang:integer_to_list(I, 16)])),
	?TRACE(ID),
	ID.

get_id(URL) ->
	<<I:160/integer>> = crypto:sha(term_to_binary(URL)),
	ID = lists:flatten(io_lib:fwrite("~40..0s", [erlang:integer_to_list(I, 16)])),
	ID.

stop() ->
	crypto:stop().
